package com.elitetyc.customview.activity;

import android.support.annotation.NonNull;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.elitetyc.customview.R;
import com.elitetyc.customview.transform.GalleryTransformer;

import java.util.ArrayList;
import java.util.List;

public class HlqhActivity extends AppCompatActivity {
    
    private ViewPager vp_main;
    private int[] mImgIds = new int[] { R.mipmap.images1,
            R.mipmap.images2, R.mipmap.images3,R.mipmap.images4 };
    private List<ImageView> mImageViews = new ArrayList<ImageView>();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_hlqh);
        initData();
        vp_main = findViewById(R.id.vp_main);

        vp_main.setAdapter(new PagerAdapter() {
            @Override
            public int getCount() {
                return mImageViews.size();
            }

            @Override
            public boolean isViewFromObject(@NonNull View view, @NonNull Object o) {
                return view==o;
            }

            @NonNull
            @Override
            public Object instantiateItem(@NonNull ViewGroup container, int position) {
                container.addView(mImageViews.get(position));
                return mImageViews.get(position);
            }

            @Override
            public void destroyItem(@NonNull ViewGroup container, int position, @NonNull Object object) {
                container.removeView(mImageViews.get(position));

            }
        });
        vp_main.setPageTransformer(true,new GalleryTransformer());
    }


    private void initData()
    {
        for (int imgId : mImgIds)
        {
            ImageView imageView = new ImageView(getApplicationContext());
            imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
            imageView.setImageResource(imgId);
            mImageViews.add(imageView);
        }
    }
}
